/*
 * Copyright 2017 hv0912
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.vimhe.ezimp2.config.bean;

import com.vimhe.ezimp2.Constants;
import com.vimhe.ezimp2.config.exception.ConfigException;
import com.vimhe.ezimp2.util.StringUtils;

import java.util.Collections;
import java.util.Map;

/**
 * 文件配置对象
 *
 * @author Vimhe
 */
public final class FileConfig {

    /**
     * 文件索引
     */
    private String index;

    /**
     * 文件路径
     */
    private String path;

    /**
     * 文件格式
     */
    private String format;

    /**
     * 工作表配置对象
     */
    private Map<Integer, SheetConfig> sheetConfigMap = Collections.emptyMap();

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        if (StringUtils.isBlank(index)) {
            throw new ConfigException("必须指定配置项【file > index】的值");
        }

        this.index = index;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        if (StringUtils.isBlank(format)) {
            format = Constants.EXCEL_FORMAT_XLSX;
        }

        if (!Constants.EXCEL_FORMAT.contains(format)) {
            throw new ConfigException("配置项【file > format】的值【" + format + "】是无效的，可选值只能是下列中的一个："
                    + Constants.EXCEL_FORMAT.toString());
        }

        this.format = format;
    }

    public Map<Integer, SheetConfig> getSheetConfigMap() {
        return sheetConfigMap;
    }

    public void setSheetConfigMap(Map<Integer, SheetConfig> sheetConfigMap) {
        this.sheetConfigMap = sheetConfigMap;
    }

}
